package de.wittje.games.mlpbd.controller;

import java.util.Locale;
import java.util.ResourceBundle;

public class ExternalizingController {

	private ResourceBundle rb;
	private Locale l;

	/**
	 * 
	 * Initializes the ExternalizingController with a language
	 * 
	 * @param l
	 *            the locale Object of the wanted language
	 */
	public ExternalizingController(Locale l) {
		this.l = l;
		rb = ResourceBundle.getBundle("Strings", l);

	}

	/**
	 * 
	 * Initializes the ExternalizingController with the default language
	 * 
	 */
	public ExternalizingController() {

		rb = ResourceBundle.getBundle("Strings", new Locale("en"));

	}

	/**
	 * Changes the language of the ResourceBundle
	 * 
	 * @param l
	 *            the new Language
	 */
	public void setLanguage(Locale l) {
		this.l = l;
		rb = ResourceBundle.getBundle("Strings", l);
	}

	/**
	 * 
	 * @param resource
	 *            name of the String to return
	 * @return the String with the given name in the chosen Language
	 * 
	 */

	public String getResource(String resource) {

		return rb.getString(resource);

	}

	/**
	 * returns the current language
	 * 
	 * @return the short term of the current language (e.g. de, en, ...)
	 */
	public String getLocale() {
		return l.getLanguage();
	}

}
